<?php
if(strlen($_SERVER["HTTP_USER_AGENT"]) < 10)exit("QQ");

include_once($_SERVER["DOCUMENT_ROOT"]."/modules/mysql_wrappers.lib.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
/*global $_Conn;

$_BetDBHost = "192.168.5.202";
$_Conn = "_ConnMaster";
global $_ConnMaster;

$_BetDBUser = "kacino";
$_BetDBPass = "cyriac_0426";
$_BetDBName = "twIPs";
$_BetWeb = $_SERVER["HTTP_HOST"];

if (! $$_Conn = @mysql_connect($_BetDBHost, $_BetDBUser, $_BetDBPass)) {
	?>
	系統維護中，請稍候再登入！不便之處，敬請見諒！！
	<!--系統維護中, 請<a href="javascript:location.reload();">重新整理</a><P>//-->
	<?php
	$email = "service@".$_BetWeb;
	$subject = " mysql_connect error (".$_BetWeb.")";
	$content = "連線錯誤：無法連線至資料庫主機！\nDBSite".$_DBSite."\nPage: ".$_SERVER["PHP_SELF"]."\n";
	mail($email, $subject, $content, "From:".$_BetWeb."<apache@secure.".$_BetWeb.">");
	exit();
}

if (! @PMA_mysql_select_db($_BetDBName, $$_Conn)) {
	?>
	系統維護中，請稍候再登入！不便之處，敬請見諒！
	<!--系統忙碌中, 請稍候片刻, 或立即<a href="javascript:location.reload();">重新整理</a>.//-->
	<script>
	function abc() {
		location.reload();
	}
	setInterval(abc,60000);
	</script>
	<?php 
	$email = "service@".$_BetWeb;
	$subject = "mysql_select_db error (".$_BetWeb.")";
	$content = "連線錯誤：無法連結資料庫！\nDBSite".$_DBSite."\nPage: ".$_SERVER["PHP_SELF"]."\n".PMA_mysql_error($$_Conn);
	$content .= "\nAccount=".$_SESSION["MemberInfo"] -> Account;
	mail($email, $subject, $content, "From:".$_BetWeb."<apache@secure.".$_BetWeb.">");
	exit();
}*/

$arrIP = split(",", $_SERVER["HTTP_X_FORWARDED_FOR"]);
$UserIP = ($arrIP[0] != "")?$arrIP[0]:$_SERVER["REMOTE_ADDR"];
$arrIP = split("\.", $UserIP);
$C_ClassIP = $arrIP[0].".".$arrIP[1].".".$arrIP[2];

$strSQL = "select ip from `ipTable` where ip = '".$C_ClassIP."' ";
$strSQL .= "union select ip from `passIPs` where ip = '".$UserIP."' ";

if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "System Error!!";	//帳號和密碼錯誤，請重新登入！
	include($_SERVER["DOCUMENT_ROOT"]."/error.php");
	exit();
}

$isPass = true;
if(PMA_mysql_num_rows($RS) > 0){
	$isPass = false;
	while($Rows = PMA_mysql_fetch_object($RS)){
		if($Rows -> ip == $UserIP){
			$isPass = true;
			break;
		}
	}
}
@mysql_close($$_Conn);

if(!$isPass){
	header("Location: /member/game/game.php");
	//print $strSQL;
	exit();
}
//print $UserIP;
?>